package com.jzo2o.customer.controller.worker;


import com.jzo2o.common.model.CurrentUserInfo;
import com.jzo2o.customer.model.dto.request.BankAccountUpsertReqDTO;
import com.jzo2o.customer.model.dto.response.BankAccountResDTO;
import com.jzo2o.customer.service.IBankAccountService;
import com.jzo2o.mvc.utils.UserContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 银行账户 前端控制器
 * </p>
 *
 * @author loe
 * @since 2024-08-14
 */
@RestController("workerBankAccountController")
@RequestMapping("/worker/bank-account")
@Api(tags = "服务银行账户接口")
public class BankAccountController {
    @Resource
    private IBankAccountService iBankAccountService;

    @PostMapping
    @ApiOperation("新增或更新银行账号信息")
    public void saveOrUpdateAccount(@RequestBody BankAccountUpsertReqDTO upsertReqDTO) {
        CurrentUserInfo currentUserInfo = UserContext.currentUser();
        upsertReqDTO.setId(currentUserInfo.getId());
        upsertReqDTO.setType(currentUserInfo.getUserType());
        iBankAccountService.saveOrUpdateAccount(upsertReqDTO);
    }

    @GetMapping("/currentUserBankAccount")
    @ApiOperation("获取当前用户银行账号")
    public BankAccountResDTO currentUserBankAccount() {
        CurrentUserInfo currentUserInfo = UserContext.currentUser();
        Long id = currentUserInfo.getId();
        return iBankAccountService.currentUserBankAccount(id);
    }

}
